package com.mianyang.zhangsan.plugin;

import com.mianyang.zhangsan.common.constant.SecConstant;
import com.mianyang.zhangsan.plugin.export.AbstractTemplate;
import com.mianyang.zhangsan.plugin.export.WordTemplate;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * @author jiangjr
 * @date 2022-12-07
 */
@Slf4j
@SpringBootTest
public class ExportClient {


    @Test
    public void generator() {
        InputStream in = null;
        File file = new File("D:\\我的\\绵阳师范学院\\毕业设计\\设计\\template.docx");
        if (file.exists()) {
            try {
                in = new FileInputStream(file);
            } catch (FileNotFoundException e) {
                // 文件读取异常
                log.error("文件读取异常");
            }
        }
        AbstractTemplate template = new WordTemplate(in);
        Map<String, Object> variables = new HashMap<>(8);
        variables.put("companyName", SecConstant.SEC_COMPANY_NAME);
        variables.put("paperName", "文化常识第一次单元测试");
        variables.put("problem1", "在古代人们怎么尊称对方妻子？");
        variables.put("answer11", "令爱");
        variables.put("answer12", "令正");
        variables.put("answer13", "令堂");
        variables.put("answer14", "令尊");
        String build = template.build(variables, "D:\\我的\\绵阳师范学院\\毕业设计\\设计\\");
        System.out.println(build);
    }
}
